﻿using Autofac;
using Autofac.Extras.DynamicProxy;
using System.Reflection;
using System.Runtime.Loader;

namespace Cmp.Web.Api
{
    /// <summary>
    /// Autofac注册服务类
    /// </summary>
    public class AutofacModuleRegister : Autofac.Module
    {
        /// <summary>
        /// 重写Load函数
        /// </summary>
        /// <param name="builder"></param>
        protected override void Load(ContainerBuilder builder)
        {
            var bllFilePath = System.IO.Path.Combine(AppContext.BaseDirectory, "Cmp.Web.Repository.dll");
            builder.RegisterAssemblyTypes(Assembly.LoadFrom(bllFilePath)).AsImplementedInterfaces().InstancePerLifetimeScope();
            bllFilePath = System.IO.Path.Combine(AppContext.BaseDirectory, "Cmp.Web.Service.dll");
            builder.RegisterAssemblyTypes(Assembly.LoadFrom(bllFilePath)).AsImplementedInterfaces().InstancePerLifetimeScope();
            bllFilePath = System.IO.Path.Combine(AppContext.BaseDirectory, "Cmp.Web.Model.dll");
            builder.RegisterAssemblyTypes(Assembly.LoadFrom(bllFilePath)).AsImplementedInterfaces().InstancePerLifetimeScope();
        }
    }
}
